<?php
Yii::import('Core.models.Category');
class SideBarCategoryListWidget extends CWidget
{
	public $type = 'article';
    public $category_id = '';
    public $hieCatIds = array();
    public $heading = '';
    public $cssClass = '';
    
    public function run()
    {
        $this->heading = trim($this->heading);
        $criteria = new CDbCriteria();
        $criteria->with = array(
            'localeCategory' => array(
                'condition' => 'locale=:locale',
                'params' => array(':locale' => Yii::app()->language)
            ),
        );
        $criteria->compare('t.is_active',1);
        $criteria->order = 't.id ASC';
        if ($this->category_id!='')
        {
            $criteria->compare('t.parent_id',$this->category_id);
            // get category title
            $langCat = LanguageCategory::model()->find('locale=:locale AND category_id=:catId',array(':locale'=>Yii::app()->language,':catId'=>$this->category_id));
            if ($this->heading=='' && !is_null($langCat))
                $this->heading = $langCat->title;   
        }
        $models = Category::model()->findAll($criteria);
        $this->render('sideBarCategoryList',array('models'=>$models));
	}
}
?>

